import 'package:flutter/material.dart';
import 'package:flutter_project/video/video_player_view.dart';
import '../common/privacy/dialog_common_view.dart';
import '../common/route_page/route_name.dart';
import '../common/utils/image_picker_utils.dart';
import '../config/app_bar_view.dart';
import '../config/theme_color.dart';

class VideoMainPage extends StatefulWidget {
  const VideoMainPage({super.key});

  @override
  State<VideoMainPage> createState() => _VideoMainPageState();
}

class _VideoMainPageState extends State<VideoMainPage> {
  String? choseImage;

  @override
  Widget build(BuildContext context) {
    return CommonAppWidget.navAppBar(
      title: '视频',
      isHiddenLeftArrow: true,
      rightActions: [
        Container(
          margin: const EdgeInsets.only(right: 15, top: 10, bottom: 10),
          height: 31,
          child: TextButton(
            style: TextButton.styleFrom(
              backgroundColor: ThemeColor.appColor,
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(5)),
              textStyle: const TextStyle(color: Colors.white, fontSize: 13),
            ),
            child: const Text(
              '播放',
              style: TextStyle(color: Colors.white),
            ),
            onPressed: () {
              if (choseImage != null) {
                clickPlayAction();
              }
            },
          ),
        )
      ],
      childWidget: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          GestureDetector(
            onTap: () {
              ImagePickerUtils.selectVideoFromAlbum(permissionBack: () {
                ConfirmAlertDialog.showView(context,
                    title: '权限设置',
                    content: '您未开启相册/存储权限，请打开相册/存储权限',
                    isShowCancelBtn: true, rightAction: () {
                  ImagePickerUtils.onTapItem();
                });
              }).then((value) {
                setState(() {
                  choseImage = value;
                  debugPrint('拿到视频的路径${choseImage!}');
                });
              });
            },
            child: Container(
              height: 335,
              alignment: Alignment.center,
              decoration: const BoxDecoration(color: Colors.white),
              child: choseImage != null
                  ? Text(choseImage ?? '')
                  : Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Image.asset(
                          "assets/images/ic_qiyeminiPhoto.png",
                          width: 37,
                          height: 31,
                          fit: BoxFit.cover,
                        ),
                        const SizedBox(
                          height: 5,
                        ),
                        const Text(
                          '+添加内容视频',
                          style: TextStyle(
                            color: Colors.grey,
                            fontSize: 16,
                          ),
                        ),
                        const SizedBox(
                          height: 5,
                        ),
                        const Text(
                          '高颜值的视频能帮助您获得更多的曝光',
                          style: TextStyle(
                            color: Colors.grey,
                            fontSize: 14,
                          ),
                        ),
                        const SizedBox(
                          height: 5,
                        ),
                        const Text(
                          '建议宽高比例为16：9',
                          style: TextStyle(
                            color: Colors.grey,
                            fontSize: 14,
                          ),
                        ),
                      ],
                    ),
            ),
          ),
        ],
      ),
    );
  }

  void clickPlayAction() {
    RouteNames.push(VideoPlayerView(
      path: choseImage ?? '',
    ));
  }
}
